home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _BED53A11DD4245D89854A1E2B5F91F81 < prev    next >
Encoding:
Text File  |  2004-01-06  |  7.5 KB  |  278 lines

  1. BaseProjectile = {
  2.     tid_cloud = System:LoadTexture("textures/cloud.jpg"),
  3.     decal_tid = System:LoadTexture("textures/decal/explo_decal.dds"),
  4.     
  5.     deleteOnGameReset=1,
  6.  
  7.     bPhysicalized = nil,
  8.     was_underwater=nil,    
  9.     
  10.     fDeformRadius = 3,
  11.     
  12.     SoundEvent = {
  13.         fVolumeRadius = 200, -- default 13
  14.         fThreat = 1, -- default 1
  15.         fInterest = 0.0,
  16.     },
  17. }
  18.  
  19. function BaseProjectile:Server_OnInit()
  20.     self.part_time = 0;
  21.     if(self.bPhysicalized==nil)then
  22.         self:CreateParticlePhys( 2, 10, 0 );
  23.         self.bPhysicalized=1;
  24.     end
  25.     
  26.     self.ExplosionParams = new(self.ExplosionParams);
  27.     
  28.     self:EnableUpdate(1);
  29.  
  30.     -- explode after a set amount of time
  31.     self:SetTimer(self.lifetime);
  32.  
  33.     self:SetPos({x=-1000,y=-1000,z=-1000});
  34. end
  35.  
  36. function BaseProjectile:Client_OnInit()
  37.     self.part_time = 0;
  38.     if(self.bPhysicalized==nil)then
  39.         self:CreateParticlePhys( 2, 10 );
  40.         self.bPhysicalized=1;
  41.     end
  42.     self:SetPhysicParams( PHYSICPARAM_PARTICLE, self.Param );
  43.     
  44.     self:EnableUpdate(1);
  45.  
  46.     self:SetViewDistRatio(255);
  47.     self:LoadObject( self.projectileObject,0, self.projectileObjectScale);
  48.     self:DrawObject( 0, 1 );
  49.  
  50.     local engineSound = self.EngineSound;
  51.     if (engineSound) then
  52.         engineSound.sound = Sound:Load3DSound(engineSound.name, 512);
  53.         Sound:SetMinMaxDistance(engineSound.sound, engineSound.minDist, engineSound.maxDist);
  54.         Sound:SetSoundLoop(engineSound.sound, 1);
  55.         self:PlaySound(engineSound.sound);
  56.     end
  57.     
  58.     -- Initialize Smoke trail particles.
  59.     --if (self.SmokeEffect) then
  60.         --self:CreateParticleEmitterEffect( 0,self.SmokeEffect,0,g_Vectors.v000,g_Vectors.v010,1 );
  61.     --end
  62. end
  63.  
  64. function BaseProjectile:Server_OnUpdate(dt)
  65.     local status=GetParticleCollisionStatus(self);
  66.     local pos=self:GetPos();
  67.     
  68.     if (status ~= nil and self.explodeOnContact == 1) then
  69.         self.isExploding = 1;
  70.     elseif (System:IsValidMapPos(pos) ~= 1) then
  71.         self.isExploding = 1;
  72.     end
  73.     
  74.     if (self.isExploding == 1) then
  75.         self.ExplosionParams.pos = pos;
  76.         Game:CreateExplosion( self.ExplosionParams );
  77.     
  78.         if (status == nil) then
  79.             status = {};
  80.             status.objtype = 0;
  81.         end
  82.         
  83.         if (status.normal == nil) then
  84.             status.normal = g_Vectors.v001;
  85.         end
  86.  
  87.         -- spawn client side effect
  88.     Server:BroadcastCommand("FX", self:GetPos(), status.normal, self.id, status.objtype);                        -- invoke OnServerCmd() on the client
  89.  
  90.         local soundEvent = self.SoundEvent;
  91.         if (soundEvent ~= nil and self.ExplosionParams.shooter~=nil) then
  92.             AI:SoundEvent(self.id, pos, soundEvent.fVolumeRadius, soundEvent.fThreat, soundEvent.fInterest, self.ExplosionParams.shooter.id);
  93.         end
  94.     
  95.         self:KillTimer();
  96.         
  97.         Server:RemoveEntity(self.id);
  98.     end
  99. end
  100.  
  101. function BaseProjectile:Client_OnUpdate(dt)
  102.     local pos = self:GetPos();
  103.     
  104.     if (self.Smoke) then
  105.         self.part_time = self.part_time + dt*2;
  106.         if (self.part_time>0.03) then        
  107.             Particle:CreateParticle(pos, g_Vectors.v000, self.Smoke);
  108.             self.part_time=0;
  109.         end
  110.     end
  111.     
  112.     if (self.SmokeEffect) then
  113.         local dir = self:GetDirectionVector();
  114.         Particle:SpawnEffect( self:GetPos(),dir,self.SmokeEffect,1 );
  115.     end
  116.  
  117.     if(Materials["mat_water"] and Materials["mat_water"].projectile_hit)then
  118.         if(self.was_underwater==nil)then
  119.             if(Game:IsPointInWater(pos)) then
  120.                 System:LogToConsole("UNDERWATER");
  121.                 self.was_underwater=1;
  122.                 ExecuteMaterial(pos, g_Vectors.v001, Materials.mat_water.projectile_hit, 1 )
  123.             end
  124.         end
  125.     end
  126.     
  127.     -- vPos, fRadius, DiffR, DiffG, DiffB, DiffA, SpecR, SpecG, SpecB, SpecA, fLifeTime
  128.     -- Commented out dynamic light for a framerate test - tig
  129.     --self:AddDynamicLight(self:GetPos(), 10, 1, 1, 0.3, 1, 1, 1, 0.3, 1, 0);
  130. end
  131.  
  132.  
  133. function BaseProjectile:Launch( weapon, shooter, pos, angles, dir, target )
  134.  
  135.     -- register with the AI system 
  136.     if (self.Param.AI_Type) then 
  137.         if (self.Param.AI_Type == AIOBJECT_ATTRIBUTE) then
  138.             AI:RegisterWithAI(self.id, AIOBJECT_ATTRIBUTE, shooter.id);
  139.         else
  140.             AI:RegisterWithAI(self.id, self.Param.AI_Type);
  141.         end
  142.     else
  143.         AI:RegisterWithAI(self.id, AIAnchor.AIOBJECT_DAMAGEGRENADE);
  144.     end
  145.  
  146.     -- special AI processing (for Mortar)
  147.     if (shooter.ai and self.useAIProjectileShoot~=nil) then
  148.         BaseProjectile.default_iv = self.Param.initial_velocity;
  149.         self.Param.initial_velocity = AI:ProjectileShoot(shooter.id,self.Param);
  150.     else
  151.         self.Param.heading = dir;
  152.     end
  153.     
  154.     self.Param.collider_to_ignore = shooter;
  155.  
  156.     self:SetPhysicParams( PHYSICPARAM_PARTICLE, self.Param );
  157.     
  158.     if (BaseProjectile.default_iv ~= nil) then
  159.         self.Param.initial_velocity = BaseProjectile.default_iv;
  160.         BaseProjectile.default_iv = nil;
  161.     end
  162.     
  163.     --[kirill] start from some helper's position - for vehicle mounted RLs
  164.     if( self.LaunchHelper ) then
  165.         pos = shooter.cnt:GetTPVHelper(0, self.LaunchHelper);
  166.     end    
  167.     
  168.     self:SetViewDistRatio(255);
  169.     self:SetPos( pos );
  170.     self:SetAngles( angles );
  171.     self.ExplosionParams.shooter = shooter;
  172.     self.ExplosionParams.weapon = weapon;
  173.     self.isExploding = nil;
  174.     
  175.     if (TargetLocker and shooter == _localplayer) then
  176.         self.Target=TargetLocker:PopTarget();    
  177.     end
  178.  
  179.     -- the ID of the server slot who 'shot' this health pack
  180.     -- used for statistics
  181.     local serverSlot = Server:GetServerSlotByEntityId(shooter.id);
  182.     
  183.     --System:Log("BaseProjectile:Launch "..tostring(shooter.id));
  184.  
  185.     if (serverSlot) then
  186.         self.shooterSSID = serverSlot:GetId();
  187.         --System:Log("BaseProjectile:Launch b");
  188.     end
  189. end
  190.  
  191. function BaseProjectile:Client_OnRemoteEffect(toktable, pos, normal, userbyte)
  192.     self:DrawObject(0,0);
  193.     
  194.     local hit = {};
  195.     hit.pos = pos;
  196.     hit.normal = normal;
  197.     hit.target_material = Materials.mat_default;
  198.     hit.play_mat_sound = 1;
  199.     hit.objtype = userbyte;
  200.     
  201.     local effect = self.matEffect;
  202.     
  203.     --objtype 2 mean "the terrain"
  204.     if (hit.objtype==2 and self.mark_terrain and (not self.was_underwater)) then
  205.         if(not self.terrain_deformed)then
  206.             self.terrain_deformed=1;
  207.             System:DeformTerrain( pos, self.fDeformRadius, self.decal_tid, self.deform_terrain);
  208.             -- in singleplayer we deform the terrain. We have to adjust the position where the
  209.             -- particle system is spawned ... otherwise it looks like it is floating in the air
  210.             if (self.deform_terrain and tonumber(s_deformable_terrain)==1) then
  211.                 hit.pos.z = hit.pos.z - 1;
  212.             end
  213.         end
  214.     end
  215.     
  216.     if (self.EngineSound and self.EngineSound.sound) then
  217.         Sound:StopSound(self.EngineSound.sound);    
  218.     end
  219.     
  220.     if(Game:IsPointInWater(hit.pos))then
  221.         hit.target_material = Materials.mat_water;
  222.         hit.normal = g_Vectors.v001;
  223.         effect = "grenade_explosion";
  224.     end
  225.     
  226.     ExecuteMaterial2(hit, effect);
  227.  
  228.     -- sound event for the radar
  229.     local soundEvent = self.SoundEvent;
  230.     if (soundEvent ~= nil) then
  231.         Game:SoundEvent(hit.pos, soundEvent.fVolumeRadius, soundEvent.fThreat, 0);
  232.     end
  233. end
  234.  
  235. BaseProjectile.Server = {
  236.     OnInit = BaseProjectile.Server_OnInit,
  237.     OnTimer = function(self)
  238.         self.isExploding = 1;
  239.     end,
  240.     OnUpdate = BaseProjectile.Server_OnUpdate,
  241. }
  242.  
  243. BaseProjectile.Client = {
  244.     OnInit = BaseProjectile.Client_OnInit,
  245.     
  246.     OnUpdate = BaseProjectile.Client_OnUpdate,
  247.     
  248.     OnRemoteEffect = BaseProjectile.Client_OnRemoteEffect,
  249. }
  250.  
  251. function CreateProjectile(projectileDefinition)
  252.     local ret=new(BaseProjectile);
  253.     
  254.     mergef(ret, projectileDefinition, 1);
  255.  
  256.     -- set some fallback default parameters    
  257.     if (ret.matEffect == nil) then
  258.         ret.matEffect = "projectile_hit";
  259.     end
  260.     if (ret.matEffectScale == nil) then
  261.         ret.matEffectScale = 1.0;
  262.     end
  263.     
  264.     if (ret.projectileObject == nil) then
  265.         ret.projectileObject = "objects/weapons/Rockets/rocket.cgf";
  266.     end
  267.     
  268.     if (ret.projectileObjectScale == nil) then
  269.         ret.projectileObjectScale = 0.5;
  270.     end
  271.  
  272.     if (ret.lifetime == nil) then
  273.         ret.lifetime = 30000;
  274.     end
  275.     
  276.     return ret;
  277. end
  278.